package com.snail.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.snail.model.dto.SubscriptionRequestDTO;
import com.snail.response.BaseResponse;
import com.snail.response.ResultUtils;
import com.snail.service.SysTeamService;
import com.snail.service.SysTeamSubscriptionService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 蔡徐坤
 * @Date 2025/7/24 11:03
 * @Description: 战队订阅控制层
 */
@RestController
@RequestMapping("subscription")
public class SysSubscriptionController {

    @Autowired
    private SysTeamService sysTeamService;

    /**
     * 订阅战队的请求
     */
    @PostMapping("subscribeTeam/{teamId}")
    public BaseResponse<Boolean> subscribeTeam(@PathVariable Long teamId, @RequestBody SubscriptionRequestDTO subscriptionRequestDTO) {
        Long userId = StpUtil.getLoginIdAsLong();
        boolean processSubscription = sysTeamService.createSubscription(userId, teamId, subscriptionRequestDTO);
        return ResultUtils.success(processSubscription);
    }

    /**
     * 取消订阅战队的请求
     */
    @DeleteMapping("unsubscribeTeam/{teamId}")
    public BaseResponse<Boolean> unsubscribeTeam(@PathVariable Long teamId) {
        Long userId = StpUtil.getLoginIdAsLong();
        boolean processUnsubscription = sysTeamService.deleteSubscription(userId, teamId);
        return ResultUtils.success(processUnsubscription);
    }

}
